﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLLMisIdeas;
using System.Drawing;

namespace MisIdeas.Ideas
{
    public partial class VerDetalle : System.Web.UI.Page
    {
        public int DetalleID
        {
            get
            {
                int id = 0;

                if (Request.QueryString["ID"] != null)
                    id = int.Parse(Request.QueryString["ID"]);

                return id;
            }
        }

        public int IdeaID
        {
            get
            {
                int id = 0;

                if (Request.QueryString["IdeaID"] != null)
                    id = int.Parse(Request.QueryString["IdeaID"]);

                return id;
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (DetalleID > 0)
                {
                    MI_IdeaDetalle detalle = new BLLIdeaDetalle().TraerDetalle(DetalleID);
                    editor.Content = detalle.MI_Descripcion;
                }
            }
        }

        protected void btnGuardar_Click(object sender, EventArgs e)
        {
            BLLIdeaDetalle bllIdeaDetalle = new BLLIdeaDetalle();
            MI_IdeaDetalle detalle = null;

            if (DetalleID == 0)
            {
                detalle = new MI_IdeaDetalle();
                detalle.MI_Descripcion = editor.Content;
                detalle.MI_IdeaID = IdeaID;
                bllIdeaDetalle.CargarDetalle(detalle);
                bllIdeaDetalle.GuardarCambios();
            }
            else
            {
                detalle = bllIdeaDetalle.TraerDetalle(DetalleID);
                detalle.MI_Descripcion = editor.Content;
                bllIdeaDetalle.ModificarDetalle(detalle);
                bllIdeaDetalle.GuardarCambios();
            }

            Response.Redirect("VerIdea.aspx?ID=" + detalle.MI_IdeaID);
        }

        protected void btnEliminar_Click(object sender, EventArgs e)
        {
            BLLIdeaDetalle bllIdeaDetalle = new BLLIdeaDetalle();
            MI_IdeaDetalle detalle = bllIdeaDetalle.TraerDetalle(DetalleID);

            bllIdeaDetalle.EliminarDetalle(DetalleID);
            bllIdeaDetalle.GuardarCambios();

            Response.Redirect("VerIdea.aspx?ID=" + detalle.MI_IdeaID);
        }

        protected void btnVolver_Click(object sender, EventArgs e)
        {
            int ideaID = 0;

            if (DetalleID == 0)
                ideaID = IdeaID;
            else
            {
                BLLIdeaDetalle bllIdeaDetalle = new BLLIdeaDetalle();
                MI_IdeaDetalle detalle = bllIdeaDetalle.TraerDetalle(DetalleID);
                ideaID = (int) detalle.MI_IdeaID;
            }

            Response.Redirect("VerIdea.aspx?ID=" + ideaID);
        }
    }
}